<?php

/**
 * ygmPerModule components.
 *
 * @package    Dev_Plugin_Permission_System
 * @subpackage ygmPerModule
 * @author     Yuri Marques <yurigmarques@gmail.com>
 * @version    SVN: $Id: component.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class ygmPerModuleComponents extends sfComponents {

    public function executeListmodules(sfWebRequest $request) {
        $Containers = array('apps', 'plugins');
        $this->dirpathapps = array();
        $id = $request->getParameter('id');
        if(!is_null($id)){
            $this->setCaminho($id);
        }else{
            $this->conteiner = '';
            $this->aplicacao = '';
            $this->modulo = '';
        }
        foreach ($Containers as $container) {
            
            $this->dirpathapps[$container]['name'] = $container;
            $this->dirpathapps[$container]['caminho'] = '/'.$container;
            $this->dirpathapps[$container]['aplicacoes'] = array();
            $diretorios = dir(sfConfig::get('sf_root_dir') . $this->dirpathapps[$container]['caminho']);
           
            while (false !== ($dirname = $diretorios->read())) {
                if ($dirname != '.' && $dirname != '..') {
                    if (is_dir(sfConfig::get('sf_root_dir') . $this->dirpathapps[$container]['caminho'] . '/' . $dirname . '/modules')) {
                        $this->dirpathapps[$container]['aplicacoes'][$dirname]['name'] = $dirname;
                        $this->dirpathapps[$container]['aplicacoes'][$dirname]['caminho'] = $this->dirpathapps[$container]['caminho'] . '/' . $dirname;

                        $subdiretorios = dir(sfConfig::get('sf_root_dir') . $this->dirpathapps[$container]['aplicacoes'][$dirname]['caminho']. '/modules');
                        $this->dirpathapps[$container]['aplicacoes'][$dirname]['modules'] = array();
                        while (false !== ($subdirname = $subdiretorios->read())) {
                            if ($subdirname != '.' && $subdirname != '..') {
                                $this->dirpathapps[$container]['aplicacoes'][$dirname]['modules'][$subdirname]['name'] = $subdirname;
                                $this->dirpathapps[$container]['aplicacoes'][$dirname]['modules'][$subdirname]['caminho'] = $this->dirpathapps[$container]['aplicacoes'][$dirname]['caminho']. '/modules/' . $subdirname;
                            }
                        }
                    }
                }
            }
            
        }
    }
    public function setCaminho($id){
        $records = Doctrine_Query::create()
                ->from('ygmPerModule')
                ->where('id=?', $id)
                ->fetchOne();
            $Caminho = explode( '/', $records->getPath());
            $this->conteiner = $Caminho[1];
            $this->aplicacao = $Caminho[2];
            $this->modulo = $Caminho[4];
    }

}

?>
